package com.creator.pangu.controller.sys;

import com.creator.pangu.base.mapper.SysPermissionMapper;
import com.creator.pangu.common.dto.LoginBody;
import com.creator.pangu.core.security.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 系统前段控制器
 *
 * @author Lijunjie
 */
@Slf4j
@RestController
public class SysController {

    @Resource
    private SysPermissionMapper sysPermissionMapper;

    @Resource
    private LoginService loginService;

    /**
     * 获取验证码
     */
    @GetMapping("captcha")
    public Map<String, Object> getCaptcha() {
        //生产验证码
        return loginService.createCaptcha();
    }

    @PostMapping("login")
    public String login(LoginBody loginBody) {
        //用户验证
        return loginService.login(loginBody);
    }

    @GetMapping("sysp")
    public Integer test() {
        return this.sysPermissionMapper.getSysPermissionListByUserId(2L).size();
    }

}
